<script>





	import Vue from 'vue'
	var date = new Date();
	var year = date.getFullYear();
	var month = date.getMonth() + 1;
	var day = date.getDate();
	var allday = date.getDate() + 1;
	var lw = new Date(date - 1000 * 60 * 60 * 24 * 30); //最后一个数字30可改，30天的意思
	var datestart = new Date(date - 1000 * 60 * 60 * 24 * 1);
	var lastY = lw.getFullYear();
	var lastM = lw.getMonth() + 1;
	var lastD = lw.getDate();
	var datestartY = datestart.getFullYear();
	var datestartM = datestart.getMonth() + 1;
	var datestartD = datestart.getDate();
	var startbefore = datestartY + "-" + (datestartM < 10 ? "0" + datestartM : datestartM) + "-" + (datestartD < 10 ? "0" +
		datestartD : datestartD);
	var startleft = lastY + "-" + (lastM < 10 ? "0" + lastM : lastM) + "-" + (lastD < 10 ? "0" + lastD : lastD); //三十天之前日期
	if (month < 10) {
		month = "0" + month;
	}
	if (day < 10) {
		day = "0" + day;
	}
	var dateright = year + "-" + month + "-" + day;
	var alldateright = year + "-" + month + "-" + allday;
	global.dateright = dateright
	console.log(global.dateright);
	global.alldateright = alldateright
	global.dateleft = startleft
	global.startbefore = startbefore
	console.log(global.dateright);
	console.log(global.dateleft);
	uni.setStorage({
		key: "LBEGINDATE",
		data: global.dateright,
		success: function() {}
	});
	global.IP = function() {
		try {
			var IP = uni.getStorageSync('IP');
			var PORT = uni.getStorageSync('PORT');
		} catch (e) {

		}
		if (IP == '' || PORT == '') {
			return false;
		} else {
			return [IP, PORT];
		}
	}
	global.isLogin = function() {
		try {
			var suid = uni.getStorageSync('lusercode');
			var srand = uni.getStorageSync('lpassword');
		} catch (e) {

		}
		if (suid == '' || srand == '') {
			return false;
		} else {
			return [suid, srand];
		}
	};
	global.falg = true
	global.Return = false
	global.Commonly = false
	global.tree = false
	global.number22 = 1
	global.userRefresh = false
	global.userinfo = ''
	global.yield = false; //员工产量报表是否显示
	global.isPush = false; //推送判断
	uni.setStorage({
		key: "opcity",
		data: 0,
		success: function() {}
	})
	uni.setStorage({
		key: "httpList",
		data: uni.getStorageSync('httpList') || ['60.173.239.156'],
		success: function() {}
	})
	uni.setStorage({
		key: "usercodeList",
		data: uni.getStorageSync('usercodeList') || ['Administrator'],
		success: function() {}
	})
	uni.setStorage({
		key: "clientid",
		data: uni.getStorageSync('clientid') || "",
		success: function() {}
	})
	// global.graceChecker = require('./colorui/components/form/graceChecker.js')
	export default {
		onLaunch: function() {
			// // #ifndef H5
			// uni.setScreenBrightness({
			// 	value: uni.getStorageSync('brightness') / 100 || 0.5,
			// });
			// // #endif
			// #ifdef APP-PLUS
			this.$store.commit('setversion', plus.runtime.version)
			// 锁定屏幕方向
			// plus.screen.lockOrientation('portrait-primary'); //锁定
			plus.screen.lockOrientation('portrait-primary');
			// #ifdef APP-PLUS  
			var info = plus.push.getClientInfo();
			console.log(info.clientid);
			/* 5+  push 消息推送 ps:使用:H5+的方式监听，实现推送*/
			plus.push.addEventListener("click", function(msg) {
				console.log("click:" + JSON.stringify(msg));
				console.log(msg.payload);
				let title = JSON.parse(msg.payload).title
				if (title == '公司公告') {
					let time = setInterval(() => {
						if (global.isPush) {
							setTimeout(() => {
								uni.navigateTo({
									url: '../Message/Message'
								})
							}, 500)
							clearInterval(time)
						}
					}, 200)
				} else if (title == '审核') {
					let time = setInterval(() => {
						if (global.isPush) {
							setTimeout(() => {
								uni.navigateTo({
									url: '../Message/Messageearlywarning'
								})
							}, 500)
							clearInterval(time)
						}
					}, 200)
				}
				let objmsg = JSON.parse(msg.payload)
				console.log(JSON.stringify(msg));
				//这里可以写跳转业务代码
			}, false);
			// 监听在线消息事件 
			plus.push.addEventListener("receive", function(msg) {
				// plus.ui.alert(2);
				//这里可以写跳转业务代码
				console.log("recevice:" + JSON.stringify(msg))
			}, false);

			// //#endif  
			// 检测升级
			console.log(plus.runtime.appid);
			console.log(plus.runtime.version);
			switch (uni.getSystemInfoSync().platform) {
				case 'android':
					console.log('运行Android上')
					uni.request({
						url: 'http://47.101.156.202:8443/huajin/checkVersion', //检查更新的服务器地址
						data: {
							appid: plus.runtime.appid,
							version: plus.runtime.version,
							// imei: plus.device.imei
						},
						success: (res) => {
							console.log('success', res);
							if (res.statusCode == 200 && res.data.code == 0) {
								let openUrl = plus.os.name === 'iOS' ? res.data.data.url : res.data.data.url;
								// 提醒用户更新
								// uni.showToast({
								//     title: '有新的版本发布，检测到您目前为Wifi连接，程序已启动自动更新。新版本下载完成后将自动弹出安装程序。',
								//     mask: false,
								//     duration: 5000,
								//     icon: "none"
								// });
								// var dtask = plus.downloader.createDownload(openUrl, {}, function(d, status) {
								//     // 下载完成  
								//     if (status == 200) {
								//         plus.runtime.install(plus.io.convertLocalFileSystemURL(d.filename), {}, {}, function(error) {
								//             uni.showToast({
								//                 title: '安装失败',
								//                 mask: false,
								//                 duration: 1500
								//             });
								//         })
								//     } else {
								//         uni.showToast({
								//             title: '更新失败',
								//             mask: false,
								//             duration: 1500
								//         });
								//     }
								// });
								// dtask.start();
								uni.showModal({
									title: '更新提示',
									content: '是否选择更新',
									success: (showResult) => {
										if (showResult.confirm) {
											plus.runtime.openURL(openUrl);
										}
									}
								})
							}
						},
						fail: (err) => {
							console.log(err);
						}
					})
					break;
				case 'ios':
					console.log('运行iOS上')
					break;
				default:
					console.log('运行在开发者工具上')
					break;
			}
			// #endif
			uni.getSystemInfo({
				success: function(e) {
					console.log(e);
					// #ifndef APP-PLUS
					// #endif
					// #ifndef MP
					Vue.prototype.StatusBar = e.statusBarHeight;
					Vue.prototype.screenHeight2 = e.screenHeight * 2,
						Vue.prototype.screenHeight = e.screenHeight
					Vue.prototype.screenWidth = e.screenWidth
					if (e.platform == 'android') {
						Vue.prototype.CustomBar = (50 * 2) + e.statusBarHeight;
					} else {
						Vue.prototype.CustomBar = (45 * 2) + e.statusBarHeight;
					};
					// #endif
					// #ifdef MP-WEIXIN
					Vue.prototype.screenHeight = e.screenHeight
					Vue.prototype.screenWidth = e.screenWidth
					Vue.prototype.StatusBar = e.statusBarHeight * 2;
					let custom = wx.getMenuButtonBoundingClientRect();
					Vue.prototype.Custom = custom;
					Vue.prototype.CustomBar = (custom.bottom + custom.top - e.statusBarHeight) * 2;
					// #endif		
					// #ifdef MP-ALIPAY
					Vue.prototype.StatusBar = e.statusBarHeight;
					Vue.prototype.CustomBar = e.statusBarHeight + e.titleBarHeight;

					// #endif
				}
			})
		},
	}
</script>

<style lang="scss">
	/*每个页面公共css */
	/* #ifndef APP-PLUS-NVUE */
	// @import '~@/static/webfont.ttf';
	@import "colorui/icon.css";
	@import "colorui/main.css";
	@import "colorui/animation.css";

	// @font-face {
	//     font-family: 'webfont';
	//     src: url('~@/static/webfont.ttf') format('truetype');;
	// }
	// @font-face {
	//   font-family: 'iconfont';
	//   font-display: swap;
	//   src: url('//at.alicdn.com/t/webfont_1nx712jndfn.eot'); /* IE9*/
	//   src: url('//at.alicdn.com/t/webfont_1nx712jndfn.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
	//   url('//at.alicdn.com/t/webfont_1nx712jndfn.woff2') format('woff2'),
	//   url('//at.alicdn.com/t/webfont_1nx712jndfn.woff') format('woff'), /* chrome、firefox */
	//   url('//at.alicdn.com/t/webfont_1nx712jndfn.ttf') format('truetype'), /* chrome、firefox、opera、Safari, Android, iOS 4.2+*/
	//   url('//at.alicdn.com/t/webfont_1nx712jndfn.svg#站酷小薇体') format('svg'); /* iOS 4.1- */
	// }
	// @font-face {
	//     font-family: 'webfont';
	//     font-display: swap;
	//     src: url('~@/static/webfont.eot'); /* IE9 */
	//     src: url('~@/static/webfont.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
	//     url('~@/static/webfont.woff2') format('woff2'),
	//     url('~@/static/webfont.woff') format('woff'), /* chrome、firefox */
	//     url('~@/static/webfont.ttf') format('truetype'), /* chrome、firefox、opera、Safari, Android, iOS 4.2+*/
	//     url('~@/static/webfont.svg#webfont') format('svg'); /* iOS 4.1- */
	// }
	page {
		background-color: #f1f5f6;
		// font-family: 'iconfont' !important;
	}

	/* #endif */
	// page {
	// 	background-color: rgba(8, 24, 50, 1) !important;
	// }
</style>
